import 'package:base_flutter/base_flutter.dart';
import 'package:flutter/src/widgets/framework.dart';
import 'package:ls_work/a_yyt/models/floor_list_entity.dart';
import 'package:ls_work/model/building_model.dart';

import '../../a_elder/models/code_value_entity.dart';
import '../../model/event_manage/event_manage_model.dart';
import '../../net/response/event_manage/event_manage_list_data.dart';
import '../model/combo_data_model.dart';

String sosPhone = "";

class EventManageListViewModel extends BaseListViewModel<EventManageListData> {
  List<FloorEntity> buildingList = [];
  List<FloorEntity> selectedBuilding = [];

  EventManageListViewModel(BuildContext context) : super(context);

  var buildingModel = BuildingModel();
  var comboModel = ComboDataModel();
  var eventTypeList = <CodeValue>[];
  var selectedType = <CodeValue>[];
  var eventModel = EventManageModel();

  @override
  Future<List<EventManageListData>> requestListData() async {
    if (buildingList.isEmpty) {
      buildingList = await buildingModel.getBuildingList(rows: 100);
    }
    if(eventTypeList.isEmpty){
      comboModel.getComboData("266213").then((value) {
        eventTypeList = value;
      });
    }
    getSosPhone();

    var typeIds = selectedType.map((e) => e.codeValue).join(",");
    var buildingIds = selectedBuilding.map((e) => e.id).join(",");
    return await eventModel.getEventList(
        buildingIds: buildingIds, eventTypes: typeIds);
  }

  @override
  void onCreated() {
    super.onCreated();
    requestRefresh();
  }

  Future<void> getSosPhone() async {
   try{
     var data =  await eventModel.getSosPhone();
     sosPhone = data.paramValue??"";
   }catch(e){

   }
  }
}
